cmake_minimum_required(VERSION 2.4.6)

if (WIN32)
		project (nidaqIO)
		set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
		#set(NIDAQ_DIR  C:\\Program\ Files\\National\ Instruments\\NI-DAQ\\DAQmx\ ANSI\ C\ Dev)
		set(NIDAQ_DIR  "C:\\Program\ Files\ (x86)\\National\ Instruments\\NI-DAQ\\DAQmx\ ANSI\ C\ Dev")
		message(${NIDAQ_DIR})
		find_library(NIDAQmxLib nidaqmx.lib HINTS ${NIDAQ_DIR}\\lib\\msvc)
		include_directories(${NIDAQ_DIR}\\include)
		message(${NIDAQmxLib})
		#############################################################################
		#daqAdapter lib+test 
		#############################################################################
		add_library(daqAdapter libDaqAdapter/daqAdapter.cpp libDaqAdapter/daqAdapter.h)
		add_executable(daqAdapterTest libDaqAdapter/daqAdapterTest.cpp)
		target_link_libraries(daqAdapterTest daqAdapter ${NIDAQmxLib})
		install(TARGETS daqAdapter daqAdapterTest DESTINATION bin)

		#############################################################################
		#cppNode
		#############################################################################
		#set(WIN_ROS_ROOT win_ros_sdk/Project)
		set(WIN_ROS_ROOT Z:\\Tingfan\\win-ros-sdk-build\\ros-sdk\\release)
		#set(WIN_ROS_ROOT Z:\\Tingfan\\win-ros-sdk\\release)

		find_package(Boost 1.44 REQUIRED COMPONENTS thread)
		message("BOOST Libs: ${Boost_LIBRARIES}")
		message("BOOST Libs DIR: ${Boost_LIBRARY_DIRS}")
		link_directories(${Boost_LIBRARY_DIRS}) #for some unknown reason, needs this line to find the to-be-linked library

		add_definitions(-DROS_BUILD_SHARED_LIBS)
		include_directories(${WIN_ROS_ROOT}\\include)
		include_directories(${Boost_INCLUDE_DIRS})
		include_directories(msg_gen\\cpp\\include)
		include_directories(libDaqAdapter)

		set(ROS_LIBS "")
		foreach(lname ros.lib;rostime.lib;rosconsole.lib;roscpp_serialization.lib)
				find_library(${lname}_path ${lname} HINTS ${WIN_ROS_ROOT}\\lib)
				set(ROS_LIBS ${ROS_LIBS} ${${lname}_path})
		endforeach(lname)
		message("${ROS_LIBS}")


		add_executable(nidaqIONode cppNode/nidaqIONode.cpp)
		target_link_libraries(nidaqIONode daqAdapter ${NIDAQmxLib} ${Boost_LIBRARIES} ${ROS_LIBS} winmm.lib)

		#add a testing environment so we could run directly on windows
		add_test(nidaqIONodeTest nidaqIONode)
		set_tests_properties(nidaqIONodeTest PROPERTIES ENVIRONMENT "PATH=win_ros_sdk\\Project;ROS_MASTER_URI=http://fukuzawa:11311")

		install(TARGETS nidaqIONode DESTINATION bin)

		#############################################################################
		# JointIO Python Library
		#############################################################################
		add_library(jointIO SHARED cppNode/jointIO.cpp cppNode/jointIO.h)
		target_link_libraries(jointIO daqAdapter ${NIDAQmxLib})
		
		add_executable(jointIOTest cppNode/jointIOTest.cpp)
		target_link_libraries(jointIOTest jointIO)
		install(TARGETS jointIO jointIOTest DESTINATION bin)

else(WIN32)
		include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

		# Set the build type.  Options are:
		#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
		#  Debug          : w/ debug symbols, w/o optimization
		#  Release        : w/o debug symbols, w/ optimization
		#  RelWithDebInfo : w/ debug symbols, w/ optimization
		#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
		#set(ROS_BUILD_TYPE RelWithDebInfo)

		rosbuild_init()

		#set the default path for built executables to the "bin" directory
		set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
		#set the default path for built libraries to the "lib" directory
		set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

		#uncomment if you have defined messages
		rosbuild_genmsg()
		#uncomment if you have defined services
		#rosbuild_gensrv()

		#common commands for building c++ executables and libraries
		#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
		#target_link_libraries(${PROJECT_NAME} another_library)
		rosbuild_add_boost_directories()
		#rosbuild_link_boost(${PROJECT_NAME} thread)
		#rosbuild_add_executable(nidaqIONode src/nidaqIONode.cpp)
		#target_link_libraries(example ${PROJECT_NAME})

		#assuming NIDAQmx.h and NIDAQmx.so are installed in /usr/local/include,lib
		find_library(NIDAQmxLib libnidaqmx.so HINTS /usr/local/lib)
		#############################################################################
		#daqAdapter lib+test 
		#############################################################################

		if (NIDAQmxLib)
			add_library(daqAdapter libDaqAdapter/daqAdapter.cpp libDaqAdapter/daqAdapter.h)
			add_executable(daqAdapterTest libDaqAdapter/daqAdapterTest.cpp)
			target_link_libraries(daqAdapterTest daqAdapter ${NIDAQmxLib})
			install(TARGETS daqAdapter daqAdapterTest DESTINATION bin)
			include_directories(libDaqAdapter)
			rosbuild_add_executable(nidaqIONode cppNode/nidaqIONode.cpp)
			target_link_libraries(nidaqIONode daqAdapter ${NIDAQmxLib})
		endif(NIDAQmxLib)

		#add_custom_target(ipc_bridge ALL COMMAND make WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/ipc" DEPENDS ROSBUILD_genmsg_cpp)
endif (WIN32)
